package org.zoomdev.zoom.aop.modules;

import org.zoomdev.zoom.aop.ProxyFactory;
import org.zoomdev.zoom.aop.ProxyObject;
import org.zoomdev.zoom.ioc.IocConstructor;
import org.zoomdev.zoom.ioc.IocKey;
import org.zoomdev.zoom.ioc.IocTypeKey;

final class ProxyConstructor implements IocConstructor {

    protected final ProxyFactory factory;

    protected final String config;

    ProxyConstructor(ProxyFactory factory, String config) {
        this.factory = factory;
        this.config = config;
    }


    @Override
    public IocKey[] getKeys(IocKey resultKey) {
        return new IocKey[]{
                new IocTypeKey(ProxyObject.class, this.config)
        };
    }

    @Override
    public Object newInstance(IocKey resultKey, Object[] args) throws Throwable {
        return factory.createObject((Class<?>) resultKey.getType(), (ProxyObject<?>) args[0]);
    }
}
